package com.zr.exception;

import com.alibaba.fastjson.JSON;
import com.zr.utils.AjaxResult;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 全局异常处理类
 */
@ControllerAdvice
public class GlobalExceptionHandler {

    @ResponseBody
    @ExceptionHandler(Exception.class)
    public String ExceptionHandler(Exception e){
        //控制台打印异常栈信息
        e.printStackTrace();
        return JSON.toJSONString(AjaxResult.fail(500, e.getMessage(), null));
    }

}
